﻿<UserControls:ScrumUserControl x:Class="ScrumTable.UI.View.WinTouch.UserControls.View.Register"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="http://schemas.microsoft.com/surface/2008"
    xmlns:Data="clr-namespace:ScrumTable.DL.Data;assembly=ScrumTable.DL.Data"
    xmlns:Converter="clr-namespace:ScrumTable.UI.View.Converter;assembly=ScrumTable.UI.View"
    xmlns:Localization="clr-namespace:ScrumTable.UI.View.Localization;assembly=ScrumTable.UI.View" xmlns:UserControls="clr-namespace:ScrumTable.UI.View.WinTouch.UserControls" xmlns:Command="clr-namespace:ScrumTable.UI.View.Command;assembly=ScrumTable.UI.View" xmlns:CustomControl="clr-namespace:ScrumTable.UI.View.WinTouch.CustomControl" Background="{StaticResource ScreenConfiguration}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
    x:Name="RegisterRoot" IsEnabled="{Binding ToastData.HasNoError}">
    <UserControls:ScrumUserControl.CommandBindings>
        <CommandBinding 
          Command="{x:Static Command:CommandLib.AddComboBoxItem}"          
          CanExecute="OnCanAddCommand"
          Executed="OnAddCommand"/>
        <CommandBinding 
          Command="{x:Static Command:CommandLib.RemoveComboBoxItem}"          
          Executed="OnRemoveCommand"/>
    </UserControls:ScrumUserControl.CommandBindings>
    <CustomControl:ScrumTableScrollViewer Margin="75,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"  MinHeight="686" Width="1024" HorizontalScrollBarVisibility="Disabled"  >
        <Grid HorizontalAlignment="Stretch">
            <Grid HorizontalAlignment="Stretch">
                <!--MaxWidth="1024"-->
                <Grid.Resources>
                    <Converter:ConverterBoolVisibility x:Key="ConverterBoolVisibility"></Converter:ConverterBoolVisibility>
                    <Converter:ConverterNotBoolVisibility x:Key="ConverterBoolNotVisibility"/>
                    <Converter:ConverterIsNullVisibility x:Key="ConverterIsNullVisibility"/>
                    <Converter:ConverterEnumVisibility x:Key="ConverterEnumVisibility"/>
                    
                    <Converter:GridHiddenWidthConverter x:Key="GridAuto" GridUnitType="Auto" InvertBool="True"/>
                    <Converter:GridHiddenWidthConverter x:Key="GridPixel" GridUnitType="Pixel" InvertBool="True"/>


                    <Converter:ConverterNotBool x:Key="ConverterNot"></Converter:ConverterNotBool>                    
                    <Style TargetType="{x:Type Label}" BasedOn="{StaticResource DescriptionLabel}"/>
                    
                    <Converter:DataAssemblyConverter x:Key="ConverterDataAssembly"/>
                    <Converter:SchemaConverter x:Key="SchemaConverter"/>

                    <DataTemplate x:Key="listTemplate">
                        <TextBlock  HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="12" FontWeight="Bold" Height="24">
                        <TextBlock.Text>
                            <Binding/>
                        </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>

                    <DataTemplate x:Key="listTemplateName">
                        <TextBlock  HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="12" FontWeight="Bold" Height="24">
                        <TextBlock.Text>
                            <Binding Path="Name"/>
                        </TextBlock.Text>
                        </TextBlock>
                    </DataTemplate>
                </Grid.Resources>
                <Grid.RowDefinitions>
                    <RowDefinition Height="0"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="8"/> 
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridAuto}}" />
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridPixel}, ConverterParameter=8}"/>
                    <RowDefinition Height="{Binding IsPathToSourceRequired, Converter={StaticResource GridAuto}}"/>
                    <RowDefinition Height="{Binding IsPathToSourceRequired, Converter={StaticResource GridPixel}, ConverterParameter=8}"/>
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridAuto}}" />
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridPixel}, ConverterParameter=8}"/>
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridAuto}}"/>
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridPixel}, ConverterParameter=8}"/> <!--10-->                    
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridPixel}, ConverterParameter=40}"/>
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridPixel}, ConverterParameter=8}"/>
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridPixel}, ConverterParameter=40}"/>
                    <RowDefinition Height="{Binding IsLoginRequired, Converter={StaticResource GridPixel}, ConverterParameter=8}"/>                    
                    <RowDefinition Height="55"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="{Binding InWizardMode, Converter={StaticResource GridPixel}, ConverterParameter=40}"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="8"/>
                    <RowDefinition Height="40"/>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0"/>
                    <ColumnDefinition Width="150" />
                    <ColumnDefinition Width="0.3*" MaxWidth="600"/>
                    <ColumnDefinition Width="300"/>               
                </Grid.ColumnDefinitions>
                <StackPanel>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.05*" MaxWidth="150"/>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition Width="0.3*" MaxWidth="600"/>
                            <ColumnDefinition Width="300"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </StackPanel>                
                <Label Grid.Column="1" Grid.Row="1" Localization:Translate.Uid="Register_ConnType" Content="{Localization:Translate}" VerticalAlignment="Top" VerticalContentAlignment="Center" Height="50"/>
             
                <Grid Grid.Row="1" Grid.Column="2"  > 
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                    </Grid.RowDefinitions>          
                    <ComboBox Grid.Row="0" MinHeight="55" Name="DataConnectionList" ItemsSource="{Binding Source={x:Static Data:DataConnectionFactory.CachedDataAssemblies}, Mode=Default}"  SelectedItem="{Binding Path=DataType, Converter={StaticResource ConverterDataAssembly}, Mode=TwoWay}" FontSize="12"  >
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <TextBlock HorizontalAlignment="Left" FontSize="12" FontWeight="Bold" Height="24">
                            <TextBlock.Text>
                                <Binding Path="Description" Mode="OneWay"/>
                            </TextBlock.Text>
                                </TextBlock>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>
                    <StackPanel Orientation="Vertical" Grid.Row="1" Name="AdvancedSettingPanel" Visibility="{Binding DriverConfig, Converter={StaticResource ResourceKey=ConverterIsNullVisibility}}"/>
                </Grid>

                <s:SurfaceButton HorizontalAlignment="Left" VerticalAlignment="Top"  Click="OnAdvancedSettingClick"  Margin="10,0,0,0" Grid.Column="3"  Grid.Row="1">
                    <UserControl Background="{StaticResource MenuIconConfigConfig}" Height="40" Width="40"/>
                </s:SurfaceButton>


                <Label Grid.Column="1" Grid.Row="3" Localization:Translate.Uid="Register_Schema" Content="{Localization:Translate}"/>

                <ComboBox Grid.Row="3" MinHeight="55" Name="DataSchemaList" ItemsSource="{Binding ElementName=DataConnectionList, Path=SelectedItem.DataSchemaSelector}" SelectedItem="{Binding Path=SchemaName, Converter={StaticResource SchemaConverter}, Mode=TwoWay}" Grid.Column="2"  FontSize="12" >
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock HorizontalAlignment="Left" FontSize="12" FontWeight="Bold" Height="24">
                        <TextBlock.Text>
                            <Binding Path="Name" />
                        </TextBlock.Text>
                            </TextBlock>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>


                <!--Server URL-->
                <Label Grid.Column="1" Grid.Row="5"  Localization:Translate.Uid="Register_ServerList" Content="{Localization:Translate}"/>
                <ComboBox VerticalContentAlignment="Center" MinHeight="55" x:Name="ServerList" ItemTemplate="{StaticResource listTemplate}" Style="{StaticResource ComboBoxStyle1}" ItemsSource="{Binding Path=ServerList}"  SelectedItem="{Binding Path=AccountManager.CurrentLoginAccount.ServerName, Mode=TwoWay}" Grid.Column="2" Grid.Row="5"/>
                <TextBlock Visibility="{Binding DataLinkType, Converter={StaticResource ConverterEnumVisibility}, ConverterParameter=Url}"  Margin="10,0,0,0" Grid.Column="3" Grid.Row="5" Text="{Localization:Translate Uid=Register_Note_Collection,Default=[Note]}" Grid.ColumnSpan="2" TextWrapping="Wrap"/>
                <StackPanel Orientation="Horizontal" Visibility="{Binding DataLinkType, Converter={StaticResource ConverterEnumVisibility}, ConverterParameter=FilePath}" Grid.Column="3" Grid.Row="5">
                    <s:SurfaceButton HorizontalAlignment="Left" VerticalAlignment="Center" Click="OnAddFilePath"  Margin="10,0,0,0" >                    
                        <UserControl Background="{StaticResource IconOpenFile}" Height="40" Width="40"/>                    
                    </s:SurfaceButton>
                    <s:SurfaceButton HorizontalAlignment="Left" VerticalAlignment="Center" Click="OnNewFilePath"  Margin="10,0,0,0">
                        <UserControl Background="{StaticResource IconNewFile}" Height="40" Width="40"/>
                    </s:SurfaceButton>
                </StackPanel>
                
                <Label Grid.Column="1" Grid.Row="7" Localization:Translate.Uid="Register_ServerUser" Content="{Localization:Translate}"/>
                <Label Grid.Column="1" Grid.Row="7" Grid.RowSpan="3" Margin="0,45,0,0"  VerticalAlignment="Top" Localization:Translate.Uid="Register_ServerPwd" Content="{Localization:Translate}"/>

                <UserControls:SurfaceDragDropListBox Grid.Column="2" Grid.Row="7" Grid.RowSpan="3" ItemsSource="{Binding Users}" x:Name="UserList"  IsItemSelectable="False" 
                                                 ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" Background="White" BorderBrush="Gray" BorderThickness="1" AllowDrop="False" CanDrag="False" SelectionMode="Single" SelectedIndex="{Binding SelectedUserIndex}">
                    <s:SurfaceListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </s:SurfaceListBox.ItemsPanel> 
                    <s:SurfaceListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Background="LightGray"  Orientation="Horizontal">
                                <StackPanel HorizontalAlignment="Left">
                                    <s:SurfaceTextBox Text="{Binding Value}" Width="80" MaxWidth="80" MinHeight="30" Height="30" MaxHeight="30" Margin="5"/>
                                    <s:SurfacePasswordBox Password="" Width="80" MaxWidth="80"  MinHeight="30" Height="30" MaxHeight="30" Margin="5" KeyDown="OnKeyDown"/>
                                </StackPanel>
                                <s:SurfaceButton Command="{Binding DataContext.RemoveUser, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}}" CommandParameter="{Binding}" Width="24" Height="24" Grid.Column="1" Background="{StaticResource IconDelete}" Margin="5" VerticalAlignment="Top" />
                            </StackPanel>
                        </DataTemplate>
                    </s:SurfaceListBox.ItemTemplate>
                </UserControls:SurfaceDragDropListBox>

                <StackPanel Margin="9,0,0,0"  Grid.Column="3" Grid.Row="7" Grid.RowSpan="3" VerticalAlignment="Center" >
                    <s:SurfaceButton Click="OnAddUserClick" HorizontalAlignment="Left">
                        <UserControl Background="{StaticResource IconAdd}" Height="40" Width="40"/>
                    </s:SurfaceButton>
                </StackPanel>




                <s:SurfaceButton Margin="0" FontSize="14" Grid.Column="2" FontWeight="Bold" Grid.Row="11" Localization:Translate.Uid="Register_ServerTest" Content="{Localization:Translate}" Click="OnSurfaceButtonClickConnect" Style="{StaticResource SurfaceButtonStyle}"/>
                <CheckBox IsEnabled="False" Background="Transparent" Grid.Column="3" Grid.Row="11" IsChecked="{Binding Path=ScrumData.IsDataContextConnected, Mode=OneWay}" Visibility="Collapsed"/>

                <Label Grid.Column="1" Grid.Row="13" Localization:Translate.Uid="Register_ServerPinOld" Content="{Localization:Translate}" Visibility="{Binding IsInChangeMode, Converter={StaticResource ConverterBoolVisibility}}"/>
                <Label Grid.Column="1" Grid.Row="13" Localization:Translate.Uid="Register_ServerPin1" Content="{Localization:Translate}"  Visibility="{Binding IsInChangeMode, Converter={StaticResource ConverterBoolNotVisibility}}"/>
                <s:SurfacePasswordBox KeyboardLayout="Numeric" Name="Pin1" Grid.Column="2" Grid.Row="13" BorderBrush="Black"  BorderThickness="1" />

                <Label Grid.Column="1" Grid.Row="15"  Localization:Translate.Uid="Register_ServerPinNew" Content="{Localization:Translate}" Visibility="{Binding IsInChangeMode, Converter={StaticResource ConverterBoolVisibility}}"/>
                <Label Grid.Column="1" Grid.Row="15"  Localization:Translate.Uid="Register_ServerPin2" Content="{Localization:Translate}" Visibility="{Binding IsInChangeMode, Converter={StaticResource ConverterBoolNotVisibility}}"/>
                <s:SurfacePasswordBox KeyboardLayout="Numeric" Name="Pin2" Grid.Column="2" Grid.Row="15" BorderBrush="Black"  BorderThickness="1" />

                <ComboBox x:Name="CurrentProject" Grid.Column="2" Grid.Row="17" Margin="0"  SelectedItem="{Binding Path=ScrumData.CurrentProject, Mode=TwoWay}" ItemsSource="{Binding Path=Projects}" ItemTemplate="{StaticResource listTemplateName}" IsEnabled="{Binding ScrumData.IsUserConnected, Mode=OneWay, Converter={StaticResource ConverterNot}}"/>

                <TextBlock Grid.Column="2" FontSize="15" Grid.Row="21" Foreground="Red"  TextWrapping="Wrap" Text="{Binding Path=ErrorConnect}"/>

                <Grid Grid.Column="2" Grid.Row="19">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition></ColumnDefinition>
                        <ColumnDefinition Width="20"></ColumnDefinition>
                        <ColumnDefinition></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <s:SurfaceButton Margin="0" FontSize="14" Grid.Column="2"  FontWeight="Bold" Click="OnSurfaceButtonClick" Style="{StaticResource SurfaceButtonStyle}">
                        <s:SurfaceButton.Content>
                            <Localization:Translate Uid="Register_Next" Default="[Save &amp; Next]" />
                        </s:SurfaceButton.Content>
                    </s:SurfaceButton>

                    <s:SurfaceButton Margin="0" Padding="0" FontSize="14" Grid.Column="0" Grid.Row="19" FontWeight="Bold" Click="OnSurfaceButtonCancelClick" Style="{StaticResource SurfaceButtonStyle}">
                        <s:SurfaceButton.Content>
                            <Localization:Translate Uid="Register_Cancel" Default="[Cancel]" />
                        </s:SurfaceButton.Content>
                    </s:SurfaceButton>

                </Grid>

            </Grid>
        </Grid>
    </CustomControl:ScrumTableScrollViewer>
</UserControls:ScrumUserControl>
